package com.ldl.customize.controller.system.controller.user;

import com.ldl.customize.entity.User;
import com.ldl.customize.service.user.UserService;
import com.ldl.customize.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	@Autowired
	private UserService userService;

	/**
	* @Title: getUserInfo
	* @Description: 查看当前用户信息
	* @param @param request
	* @param @param model
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	@RequestMapping(value = "/userInfo", method = RequestMethod.GET)
	public String getUserInfo(HttpServletRequest request,Model model) {
		HttpSession session = request.getSession();
		String usernameString =  session.getAttribute(Constants.SESSION_USERNAME).toString();
		User user = userService.getUserByName(usernameString);
		model.addAttribute("user", user);
		return "user/user_info";
	}

	/**
	* @Title: goHome
	* @Description: 返回首页
	* @param @param request
	* @param @param model
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	@RequestMapping(value = "/goHome", method = RequestMethod.GET)
	public String goHome(HttpServletRequest request,Model model) {

		HttpSession session = request.getSession();
		model.addAttribute("username", session.getAttribute(Constants.SESSION_USERNAME).toString());
		return "index";
	}
	/**
	 *
	* @Title: changeInfo
	* @Description: 修改用户信息
	* @param @param user
	* @param @param model
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	@RequestMapping(value = "/changeInfo", method = RequestMethod.POST)
	public String changeInfo(@ModelAttribute User user ,Model model) {
		model.addAttribute("flag", "1");
		return "index";
	}

}
